﻿
namespace n_EventIns
{
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

using n_MyIns;
using n_GUIcoder;
using n_MyObject;
using n_UserModule;
using n_GUIset;
using n_CondiEndIns;
using n_Shape;
using n_MyFileObject;
using n_MainSystemData;

//*****************************************************
//逻辑流程组件类
public class EventIns: MyIns
{
	const int OffetWidth = 5;
	
	string vvEventEntry;
	public string EventEntry {
		get { return vvEventEntry; }
		set {
			vvEventEntry = value;
			
			/*
			string[] c = vvEventEntry.Split( '_' );
			EventSource = c[ 0 ];
			EventType = c[ 1 ];
			*/
			
			int LastSp = vvEventEntry.LastIndexOf( "_" );
			EventSource = vvEventEntry.Remove( LastSp );
			EventType = vvEventEntry.Remove( 0, LastSp + 1 );
			
			HeadWidth = (int)GUIset.mg.MeasureString( EventSource, GUIset.ExpFont ).Width;
			Width = (int)GUIset.mg.MeasureString( vvEventEntry, GUIset.ExpFont ).Width + 8 + OffetWidth;
		}
	}
	
	int HeadWidth;
	
	//注意这两个是只读的
	public string EventSource;
	public string EventType;
	public MyFileObject owner;
	
	public bool isDeleted;
	
	public CondiEndIns InsEnd;
	
	
	//构造函数
	public EventIns(): base()
	{
		this.Width = 200;
		this.Height = 35;
		
		isDeleted = false;
	}
	
	//设置用户参数
	public void SetUserValue( string vName, string vGroupMes, string vMes, int vX, int vY, int vAngle, bool sf )
	{
		Name = vName;
		GroupMes = vGroupMes;
		EventEntry = vMes;
		SX = vX;
		SY = vY;
		
		Height = GUIset.ExpFont.Height + 4;
		ExYHPadding = Height / 2;
		ShowFollow = sf;
		
		//if( !ShowFollow ) {
		//	SetFollowVisible( ShowFollow );
		//}
	}
	
	public override void UserMouseClick( int mX, int mY )
	{
		ShowFollow = !ShowFollow;
		SetFollowVisible( ShowFollow );
	}
	
	public override void UserMouseMove( bool isMouseOn, int mX, int mY )
	{
		
	}
	
	//组件绘制工作1
	//绘制组件的外形等,基础绘制工作
	public override void Draw1( Graphics g )
	{
		if( isNewTick != 0 ) {
			return;
		}
		Brush b = EventBackColor;
		if( owner == null || isNote ) {
			b = Brushes.Silver;
		}
		
		//绘制竖直连线
		if( ShowFollow ) {
			g.FillRectangle( b, SX, SY + LineOffset, 5, this.InsEnd.SY - this.SY );
		}
		else {
			int Hei = Height * 2 / 3;
			
			/*
			if( SystemData.isBlack ) {
				g.FillEllipse( Brushes.Yellow, StartX + SX - 2 - Hei, StartY + SY + ( + Height - Hei)/2, Hei, Hei );
			}
			else {
				g.FillEllipse( Brushes.Green, StartX + SX - 2 - Hei, StartY + SY + ( + Height - Hei)/2, Hei, Hei );
			}
			*/
			g.DrawString( "点击上方事件框可展开", GUIset.ExpFont, Brushes.DarkSlateGray, SX, SY + 6 + Height );
		}
		
		//绘制表达式位图
		Rectangle r = new Rectangle( SX, SY, this.Width, this.Height );
		GraphicsPath gp = Shape.CreateRoundedRectanglePath( r );
		g.FillPath( b, gp );
		//g.DrawPath( Pens.WhiteSmoke, gp );
		//g.DrawString( EventEntry, GUIset.ExpFont, Brushes.Black, StartX + X - this.Width / 2 + 4, StartY + Y - this.Height / 2 + 2 );
		
		int eh = this.Height / 2;
		
		//绘制三角填充区
		Rectangle r1 = new Rectangle( SX, SY - eh, HeadWidth + 4 + OffetWidth*2, this.Height + eh );
		GraphicsPath gp1 = Shape.CreateRoundedRectanglePath( r1 );
		g.FillPath( b, gp1 );
		GraphicsPath BackPath = new GraphicsPath();
		BackPath.Reset();
		int HWidth = SX + HeadWidth + OffetWidth*2 + 1;
		Point point1 = new Point( HWidth, SY - eh );
		Point point2 = new Point( HWidth, SY + 1 );
		//Point point3 = new Point( HWidth + Height, StartY + SY + 1 );
		Point point3 = new Point( SX + Width, SY + 1 );
		Point[] pntArr = { point1, point2, point3 };
		BackPath.AddPolygon( pntArr );
		g.FillPath( b, BackPath );
		
		//填充头部矩形
		Rectangle rr = new Rectangle( SX + 1 + OffetWidth, SY + 1 - 0, HeadWidth + 2, this.Height - 2 );
		GraphicsPath gp2 = Shape.CreateRoundedRectanglePath( rr );
		//g.DrawPath( Pens.Green, gp2 );
		if( owner == null || isNote ) {
			g.FillPath( Brushes.Gray, gp2 );
		}
		else if( SystemData.isBlack ) {
			g.FillPath( Brushes.ForestGreen, gp2 );
		}
		else {
			g.FillPath( Brushes.BurlyWood, gp2 );
		}
		
		/*
		//绘制顶端效果线段
		g.FillRectangle( Brushes.PeachPuff, StartX + SX + 1 + OffetWidth + 3, StartY + SY + 3 - eh, HeadWidth + 2 - 6, 2 );
		*/
		
		g.DrawString( EventSource, GUIset.ExpFont, EventForeColor, SX + 4 + OffetWidth, SY + 2 );
		g.DrawString( EventType, GUIset.ExpFont, EventForeColor, SX + HeadWidth + 4 + OffetWidth, SY + 2 );
	}
}
}


